package com.woniuxy.oldmanapi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.entity.Contract;
import com.woniuxy.oldmanapi.mapper.ContractMapper;
import com.woniuxy.oldmanapi.yvo.ContractVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContractService {
    @Autowired
    ContractMapper contractMapper;

    public List<Contract> selectAllContract() {
        return contractMapper.selectAll();
    }
    public PageInfo<ContractVo> initSelectAllByCons(String name, int now, int size) {
        PageHelper.startPage(now, size);
        List<ContractVo> arr = contractMapper.initSelectAllByCons(name);
        return new PageInfo<>(arr);
    }

    //删除
    public void deleteContract(int id) {
        contractMapper.deleteByPrimaryKey(id);
    }

    public void modifyContractStatus(int id, int status) {
        contractMapper.modifyContractStatus(id,status);

    }

    public void addContract(Contract contract) {
        contract.setContractstatus(1);
        contractMapper.insert(contract);
    }

    public void modifyContract(Contract contract) {
        contractMapper.updateByPrimaryKey(contract);
    }

    public ContractVo selectContractById(int id) {
        return contractMapper.selectContractById(id);
    }
}
